<?php
/**
 * 微信账户管理
 * 跃飞科技版权所有 @2017
 * User: 钟贵廷
 * Date: 2017/5/20
 * Time: 10:53
 */

namespace app\admin\controller;

class Account extends Admin
{
    /*
     * 长链接转短链接接口
     */
    public function shortUrl()
    {
        $access_token = $this->get_access_token();
        $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$access_token}";
        $long_url = "http://www.yeafy.com/index.php/Home/Index/aboutUs.html";
        $data = json_encode(['action'=>'long2short','long_url'=>$long_url]);
        $res =$this->https_request($url,$data);
        p($res);
    }

    /**
     * 创建二维码ticket
     * 通过ticket换取二维码
     */
    public function qrCodeCreate()
    {
        $access_token = $this->get_access_token();
        $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$access_token}";
        $data = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}';
        $res =$this->https_request($url,$data);
        $ticket = urlencode($res['ticket']);
        //通过ticket换取二维码
        $url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={$ticket}";
        echo "<img src='$url'>";
    }

}